package com.hbx.residential_service.dao;

import com.hbx.residential_service.domain.Pay;
import com.hbx.residential_service.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface PayDao {
    @Select("select * from pays")
    @Results({
            @Result(id=true,property = "payId",column = "payId"),
            @Result(property = "payType",column = "payType"),
            @Result(property = "payMoney",column = "payMoney"),
            @Result(property = "payStatus",column = "payStatus"),
            @Result(property = "payDate",column = "payDate"),
            @Result(property = "user",column = "payUserId",javaType = User.class,one = @One(select = "com.hbx.residential_service.dao.UserDao.findById"))
    })
    List<Pay> findAll(int page, int size);

    @Insert("insert into pays(payType,payMoney,payStatus,payUserId) values(#{payType},#{payMoney},#{payStatus},#{user.userid})")
    void addPay(Pay pay);

    @Delete("delete from pays where payId=#{payId}")
    void deletePay(int payId);

    @Select("select * from pays where payId=#{payId}")
    @Results({
            @Result(id=true,property = "houseId",column = "houseId"),
            @Result(property = "houseNum",column = "houseNum"),
            @Result(property = "houseBuild",column = "houseBuild"),
            @Result(property = "houseStatus",column = "houseStatus"),
            @Result(property = "houseDate",column = "houseDate"),
            @Result(property = "user",column = "houseUserId",javaType = User.class,one = @One(select = "com.hbx.residential_service.dao.UserDao.findById"))
    })
    Pay findUpdPayById(int payId);

    @Update("update pays set payType=#{payType},payMoney=#{payMoney},payStatus=#{payStatus},payUserId=#{user.userid} where payId=#{payId}")
    void UpdateById(Pay pay);

    @Select("select * from pays where payUserId in (select userid from owners where username like #{content})")
    @Results({
            @Result(id=true,property = "payId",column = "payId"),
            @Result(property = "payType",column = "payType"),
            @Result(property = "payMoney",column = "payMoney"),
            @Result(property = "payStatus",column = "payStatus"),
//            @Result(property = "payDate",column = "payDate"),
            @Result(property = "user",column = "payUserId",javaType = User.class,one = @One(select = "com.hbx.residential_service.dao.UserDao.findById"))
    })
    List<Pay> fsByUsername(@Param("content") String content,@Param("page") int page, @Param("size") int size);

    @Select("select * from pays where payStatus=0")
    @Results({
            @Result(id=true,property = "payId",column = "payId"),
            @Result(property = "payType",column = "payType"),
            @Result(property = "payMoney",column = "payMoney"),
            @Result(property = "payStatus",column = "payStatus"),
//            @Result(property = "payDate",column = "payDate"),
            @Result(property = "user",column = "payUserId",javaType = User.class,one = @One(select = "com.hbx.residential_service.dao.UserDao.findById"))
    })
    List<Pay> findByUnpaid(int page, int size);
}
